//
//  SettingVC.m
//  PlayShow
//
//  Created by hff on 2018/4/23.
//  Copyright © 2018年 threeTi. All rights reserved.
//

#import "SettingVC.h"
#import "SettingCell.h"
#import "AppMacro.h"
#import "UIColor+Utils.h"
#import "HUD.h"

@interface SettingVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *settingTableView;//设置列表
@property (strong, nonatomic) NSMutableArray *dataArray;//设置文本数据
@property (strong, nonatomic) NSMutableArray *imagesArray;//设置图标数据
@property (strong, nonatomic) UIButton *logoutBtn;//退出登陆

@end

@implementation SettingVC

-(NSMutableArray *)imagesArray
{
    if (!_imagesArray) {
        _imagesArray = [NSMutableArray arrayWithObjects:@"clean.png",@"other.png",@"about.png", nil];
    }
    return _imagesArray;
}

-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithObjects:@"清理缓存",@"其它设置",@"关于樱桃商学院", nil];
    }
    return _dataArray;
}

-(UIButton *)logoutBtn
{
    if (!_logoutBtn)
    {
        _logoutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_logoutBtn setFrame:CGRectMake(15, 15, UIScreenWidth-30, 48)];
        [_logoutBtn  setTitle:@"退出登录" forState:UIControlStateNormal];
        [_logoutBtn setBackgroundColor:[UIColor colorForHex:PINK_COCOR]];
        [_logoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_logoutBtn.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        
        [_logoutBtn.layer setCornerRadius:10];
        [_logoutBtn.layer setMasksToBounds:YES];
        
        [_logoutBtn addTarget:self action:@selector(quitBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    }
    return _logoutBtn;
}

-(void)quitBtnClicked
{
     [HUD showAlertWithTitle:DEFAULT_ALERT_MESSAGE];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"设置";
    
    //注册自定义cell
    [self.settingTableView registerNib:[UINib nibWithNibName:@"SettingCell"  bundle:nil] forCellReuseIdentifier:@"SettingCell" ];
    [self.settingTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.settingTableView setBackgroundColor:[UIColor clearColor]];
    
    //退出登录按钮
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 70)];
    [footerView addSubview:self.logoutBtn];
    [self.settingTableView setTableFooterView:footerView];
}


#pragma mark *** tableView_delegate  ***
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell.contentView setBackgroundColor:[UIColor whiteColor]];
    
    [cell.settingImage setImage:[UIImage imageNamed:[self.imagesArray objectAtIndex:indexPath.row]]];
    [cell.settingTitle setText:[self.dataArray objectAtIndex:indexPath.row]];
    
    return cell;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  [self.dataArray count];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 48;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      [HUD showAlertWithTitle:DEFAULT_ALERT_MESSAGE];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
